using System.Collections.Generic;
using XNgine.CameraManagement;
using XNgine.Services;

namespace XNgine.RenderManagement
{
    public class RenderManager : IRenderManagement
    {
        public IRenderableObjectsProvider RenderableObjectsProvider { get; private set; }

        public RenderManager(IRenderableObjectsProvider renderableObjectsProvider)
        {
            RenderableObjectsProvider = renderableObjectsProvider;
        }

        public void RenderObjects()
        {
            ICamera camera = XEngine.Instance.GetService<ICameraManagement>().ActiveCamera;

            IEnumerable<PositionedRenderable> renderables =
                RenderableObjectsProvider.GetObjectsForRendering(camera.Frustum);

            foreach (PositionedRenderable renderable in renderables)
            {
                renderable.Render();
            }
        }
    }
}